package com.ruoyi.develop.orderIronDetail.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.develop.projectBaseInfo.domain.ProjectBaseInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.orderIronDetail.domain.OrderIronDetail;
import com.ruoyi.develop.orderIronDetail.service.IOrderIronDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 铁附件订单拆解明细Controller
 * @author lmm
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/orderIronDetail/orderIronDetail")
public class OrderIronDetailController extends BaseController {
    @Autowired
    private IOrderIronDetailService orderIronDetailService;

    /**
     * 查询铁附件订单拆解明细列表
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderIronDetail:query')")
    @GetMapping("/list")
    public TableDataInfo list(OrderIronDetail entity) {
        startPage();
        List<OrderIronDetail> list = orderIronDetailService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出铁附件订单拆解明细列表
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderIronDetail:export')")
    @Log(title = "铁附件订单拆解明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderIronDetail entity) {
        List<OrderIronDetail> list = orderIronDetailService.selectList(entity);
        ExcelUtil<OrderIronDetail> util = new ExcelUtil<OrderIronDetail>(OrderIronDetail. class);
        util.exportExcel(response, list, "铁附件订单拆解明细数据");
    }

    /**
     * 获取铁附件订单拆解明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderIronDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(orderIronDetailService.selectById(id));
    }

    /**
     * 新增铁附件订单拆解明细
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderIronDetail:add')")
    @Log(title = "铁附件订单拆解明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody OrderIronDetail entity) {
        return toAjax(orderIronDetailService.insert(entity));
    }

    /**
     * 修改铁附件订单拆解明细
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderIronDetail:edit')")
    @Log(title = "铁附件订单拆解明细", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody OrderIronDetail entity) {
        return toAjax(orderIronDetailService.update(entity));
    }

    /**
     * 删除铁附件订单拆解明细
     */
    @PreAuthorize("@ss.hasPermi('develop:OrderIronDetail:remove')")
    @Log(title = "铁附件订单拆解明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(orderIronDetailService.deleteByIds(ids));
    }

    @Log(title = "铁件信息导入数据", businessType = BusinessType.INSERT)
    @PostMapping("/importData")
    public AjaxResult importData(OrderIronDetail entity, MultipartFile file) {
        if (StringUtils.isBlank(entity.getArea())) {
            AjaxResult.error("上传参数有误！");
        }
        Map<String, Object> error = new HashMap<>();
        error = orderIronDetailService.importData(entity,file);
        error.put("code", 200);
        return AjaxResult.success(error);
    }

}
